Imports SchemaCodeGen

Partial Public Class pages_Contents_usercontrols_UCContents : Inherits UserControl

#Region "Constants"
	Public Const REMAINING_TEXT As String = "Remaining"
	Public Const SELECTED_TEXT As String = "Selected"
#End Region

#Region "Interface for Search page"
	'Selected TemplateSets
	Public Sub Display(ByVal results As CContentList)

		litCount.Text = results.Count.ToString("n0")
		For Each i As CContent In ctrlPaging.Display(results)
			UCContent(plh).Display(i, results.IndexOf(i) + 1)
		Next
	End Sub
#End Region

#Region "Interface for Templates page"
	'Remaining TemplateSets
	Public Sub DisplayRemaining(ByVal template As CTemplate, Optional ByVal search As String = Nothing)
		colDate1.Visible = False
		colDate2.Visible = False
		colHash.Visible = False
		colLength.Visible = False
		colTemplate.Visible = False

		Dim filtered As CTemplateSetList = template.Contents.RemainingTemplateSets(search)
		litCount.Text = filtered.Count.ToString()
		Me.Visible = filtered.Count > 0

		For Each i As CTemplateSet In ctrlPaging.Display(filtered)
			UCContent(plh).Display(i, template.TemplateId, Nothing, filtered.IndexOf(i) + 1)
		Next
	End Sub
	'Selected TemplateSets
	Public Sub DisplaySelected(ByVal template As CTemplate)
		colTemplate.Visible = False

		Dim selected As CContentList = template.Contents
		litCount.Text = selected.Count.ToString()
		For Each i As CContent In ctrlPaging.Display(selected)
			UCContent(plh).Display(i.TemplateSet, i.ContentTemplateId, i, selected.IndexOf(i) + 1)
		Next
	End Sub
#End Region

#Region "Interface for TemplateSets page"
	'Remaining Templates
	Public Sub DisplayRemaining(ByVal templateSet As CTemplateSet, Optional ByVal search As String = Nothing)
		colDate1.Visible = False
		colDate2.Visible = False
		colHash.Visible = False
		colLength.Visible = False
		colPattern.Visible = False

		Dim filtered As CTemplateList = templateSet.Contents.RemainingTemplates(search)
		litCount.Text = filtered.Count.ToString()
		Me.Visible = filtered.Count > 0

		For Each i As CTemplate In ctrlPaging.Display(filtered)
			UCContent(plh).Display(i, templateSet.SetId, Nothing, filtered.IndexOf(i) + 1)
		Next
	End Sub
	'Selected Templates
	Public Sub DisplaySelected(ByVal templateSet As CTemplateSet)
		colPattern.Visible = False

		Dim selected As CContentList = templateSet.Contents
		litCount.Text = selected.Count.ToString()
		For Each i As CContent In ctrlPaging.Display(selected)
			UCContent(plh).Display(i.Template, i.ContentSetId, i, selected.IndexOf(i) + 1)
		Next
	End Sub
#End Region

#Region "User Controls"
	Private Function UCContent(ByVal target As Control) As pages_Contents_usercontrols_UCContent
		Dim ctrl As pages_Contents_usercontrols_UCContent = Page.LoadControl(CSitemap.UCContent)
		target.Controls.Add(ctrl)
		Return ctrl
	End Function
#End Region


#Region "Paging"
	Public ReadOnly Property PagingInfo() As CPagingInfo
		Get
			Return ctrlPaging.Info
		End Get
	End Property
	Public Property QueryString() As String
		Get
			Return ctrlPaging.QueryString
		End Get
		Set(ByVal value As String)
			ctrlPaging.QueryString = value
		End Set
	End Property
	Public Property PageSize() As Integer
		Get
			Return ctrlPaging.PageSize
		End Get
		Set(ByVal value As Integer)
			ctrlPaging.PageSize = value
		End Set
	End Property
	Public WriteOnly Property FriendlyUrl() As String
		Set(ByVal value As String)
			ctrlPaging.FriendlyUrl = String.Concat(value, IIf(value.Contains("?"), "&", "?"), QueryString, "={0}")
		End Set
	End Property
#End Region

End Class